public class Test {
    public static int binarySearch(int[] arrays,int find){
        int left=0;
        int right =arrays.length-1;
        while(right>=left){
            int ret=(right+left)/2;
            if(arrays[ret]<find){
                left=ret+1;
            }else if(arrays[ret]>find){
                right=ret-1;
            }
            else{
                return ret;
            }
        }
        return -1;
    }
    public static void main(String[] args) {
        int[] array = {1,2,31,4,15};
        int index = binarySearch(array,31);
        System.out.println(index);
    }
}
